<template>
    <div>
        <input type="text" v-model="ps.name" placeholder="房号名称">
        <input type="date" v-model="ps.d1">-
        <input type="date" v-model="ps.d2">
        <input type="button" value="查询" @click="Show">
        <table class="table">
            <thead>
                <tr>
                    <td>房屋类型</td>
                    <td>房屋号</td>
                    <td>房屋状态</td>
                    <td>入住时间</td>
                    <td>是否入住</td>
                    <td>操作</td>
                </tr>
            </thead>

            <tbody>
                <tr v-for="a in dataa">
                    <td>{{a.houseTypeName}}</td>
                    <td>{{a.houseNumName}}</td>
                    <td>{{a.states?"上架":"下架"}}</td>
                    <td>{{moment(a.createTime).format("YYYY-MM-DD HH:MM")}}</td>
                    <td>{{a.houseState==1?"空闲":"已入住"}}</td>
                    <td>
                        <input type="button" value="修改" @click="update(a.houseNumId)">
                        <input type="button" value="下架" @click="UpdateState(a.houseNumId)">
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import { onMounted,ref } from 'vue';
import { useRouter } from 'vue-router';
import moment from 'moment';
const router = useRouter();


const update=(val:any)=>{
    router.push({path:"/UpdateNumView",query:{id:val}})
}

const UpdateState=(val:any)=>{
    if(!confirm("确认下架吗?"))
    {
        return;
    }
    axios.get("https://localhost:7189/api/House/UpdateState",{params:{id:val}}).then((res)=>{
        if(res.data>0)
        {
            alert("下架成功");
            Show();
        }
        else
        {
            alert("下架失败")
        }
    })
}


onMounted(()=>{
    Show();
})

const dataa = ref([{
    "houseNumId":0,
    "houseNumName": "",
    "states": false,
    "createTime": "2025-08-07T01:26:55.679",
    "houseTypeId": 0,
    "houseTypeName": "",
    "houseState": 0
}])

const ps = ref({
    name:"",
    d1:"",
    d2:""
})

const Show=()=>{
    axios.get("https://localhost:7189/api/House/Show",{params:ps.value}).then((res)=>{
        dataa.value = res.data;
    })
}
</script>

<style scoped>

</style>